<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <link rel="stylesheet" href="styles/style.css">
        <link rel="stylesheet" href="styles/theme/atom-one-dark.css">
        <title>例子9-ES6/7常用语法介绍</title>
    </head>
    <body>
        <pre>
            <code>
                // 例子9

                let [foo = true] = [];
                console.log(foo); // true

                //--------------------------------------------------------------------------

                let [x, y = 'y'] = ['x'];
                console.log(x, y); // "x" "y"

                //--------------------------------------------------------------------------

                let [a, b = 'b'] = ['a', undefined];
                console.log(a, b); // "a" "b"

                //--------------------------------------------------------------------------

                let [z = 1] = [null];
                console.log(z); // null

                //--------------------------------------------------------------------------

                function fn(x) {
                    console.log(x);
                    return x;
                }
                let [bar = fn('bar')] = [1];
                let [baz = fn('baz')] = [];
                console.log(bar, baz); // 1 "baz", 这里bar中的fn('bar')并没有执行

                //--------------------------------------------------------------------------

                let [x1 = 1, y1 = x1] = [];
                console.log(x1, y1); // 1 1

                let [x2 = 1, y2 = x2] = [2];
                console.log(x2, y2); // 2 2

                let [x3 = 1, y3 = x3] = [5, 10];
                console.log(x3, y3); // 5 10

                let [x4 = y4, y4 = 1] = [2];
                console.log(x4, y4); // 2 1

                let [x5 = y5, y5 = 1] = [];
                console.log(x5, y5); // Uncaught ReferenceError: y5 is not defined
            </code>
        </pre>
        <script src="scripts/libs/highlight.pack.js"></script>
        <script src="scripts/9.js"></script>
        <script>
            hljs.initHighlightingOnLoad();
        </script>
    </body>
</html>